package net.sureon.common.security;

/**
 * privilege object, static definition object.
 * 
 * @author jason
 *
 */
public class Privilege {
	public static final int USER_CATEGORY = 1;
	public static final int GROUP_CATEGORY = 2;
	public static final int COMPANY_CATEGORY = 3;
	
	private final int category;
	private final String name;

	public static final Privilege USER_R = new Privilege(USER_CATEGORY, "ReadUser");
	public static final Privilege USER_W = new Privilege(USER_CATEGORY, "WriteUser");
	public static final Privilege GROUP_R = new Privilege(GROUP_CATEGORY, "ReadGroup");
	public static final Privilege GROUP_W = new Privilege(GROUP_CATEGORY, "WriteGroup");
	public static final Privilege COMPANY_R = new Privilege(COMPANY_CATEGORY, "ReadCompany");
	public static final Privilege COMPANY_W = new Privilege(COMPANY_CATEGORY, "WriteCompany");
	public static final Privilege SYSTEM_W = new Privilege(COMPANY_CATEGORY, "WriteSystem");
	
	private Privilege(int category, String name) {
		this.category = category;
		this.name = name;
	}

	/**
	 * @return the category
	 */
	public int getCategory() {
		return category;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + category;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Privilege other = (Privilege) obj;
		if (category != other.category)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	
	public String toString(){
		return name + ":" + category;
	}

}
